(function($) {
	var $this = null;
	var messageId = 0;
	$(function() {
		var messageReplyDivHtm = "<div id=\"messageReplyListPanel_yinying\" class=\"yinying\" style='z-index:700;'></div><div id=\"messageReplyListPanel\" style='z-index:701;' class=\"hideDiv\">" + "<div style=\"float:right;margin-bottom:5px;width:20px;height:20px;line-height:20px;" + "text-align:center;background-color:#eee;margin-bottom:5px;border:1px solid #ccc;\" >" + " <span style=\"cursor: pointer;font-size: 14px;\"  id=\"messageReplyListPanel_close\" >X</span>" + " </div><table   id=\"messageReplyListPanel_data\" cellpadding=\"4\" cellspacing=\"0\" border=\"1\" width=\"100%\">" + "<thead><tr><th>回复时间</th><th>回复内容</th><th>回复人</th></tr><tbody></tbody></thead></table><div id=\"messageReplyPager\" class='pager'></div></div>";
		$("body").prepend(messageReplyDivHtm);
		$("#messageReplyListPanel_close").bind("click", closeMessageReplyListPanel);
		// 关闭
		$("#messageReplyListPanel_search").bind("click", _messageReplySelectedSearch);
		// 查询
	});
	/**
	 * 显示商铺列表层
	 */
	function openMessageReplyListPanel(id) {
		messageId = id;
		_messageReplySelectedSearch()
		$("#messageReplyListPanel, #messageReplyListPanel_yinying").show();
		addMargin($("#messageReplyListPanel"));
	}

	/**
	 * 加载数据
	 */
	function _messageReplySelectedSearch() {
		new Pagination({
			method : 'get', // 请求方法 post|get
			type : 'json', // 返回内容格式，json|text //NOT SUPPORT
			url : '../WxCustomerReplayMsg/find/selectOfReply', // 请求地址，注意函数会自定添加分页的两个参数 ‘0/10’
			data : {
				'id' : messageId
			}, // 使用post 方法是的请求参数
			pageSize : 10, // 页面大小
			startIndex : 0, // 服务器提供的接口页码是从几开始的，建议从0开始
			success : printDataToPage, // state 为 0 时，回调
			pagerHandler : 'messageReplyPager', // 显示分页的 div 的 id
			last : last
		});
	}

	function last(message) {
		$("#messageReplyListPanel, #messageReplyListPanel_yinying").show();
		addMargin($("#messageReplyListPanel"));
	}

	function printDataToPage(message) {

		var $tbody = $("#messageReplyListPanel_data tbody");
		$tbody.empty();
		// 清空数据
		var len = message.result.data.length;
		// 返回条目数
		for (var i = 0; i < len; i++) {
			// "id", "name","mp","contact");
			var replyTime = getHtmlString(getHeadIndexValue(i, message, 'replyTime'));
			var replyContent = getHtmlString(getHeadIndexValue(i, message, 'replyContent'));
			var replyer = getHtmlString(getHeadIndexValue(i, message, 'replyer'));

/*			var select = "<td><input class=\"common_btn\" type=\"button\" onclick=\"__messageReplySelected('" + id + "','" + name + "','" + mp + "')\" value=\"选择\"></input></td>";
*/
			var tr = "<tr>" + "<td>" + replyTime + "</td>" + "<td>" + replyContent + "</td>" + "<td>" + replyer + "</td></tr>";
			$tbody.append($(tr));
		}
	}

	/**
	 * 关闭
	 */
	function closeMessageReplyListPanel() {
		$("#messageReplyListPanel, #messageReplyListPanel_yinying").hide();
	}

	/**
	 * 选择并关闭
	 */
	function __messageReplySelected(messageReplyId, messageReplyName,mp) {
		$this.empty();
		$this.append("<option value='" + messageReplyId + "' selected=\"selected\" >" + messageReplyName + "</option>");
		$("#messageReplyListPanel, #messageReplyListPanel_yinying").hide();

		if (window.messageReplySelected) {
			window.messageReplySelected(messageReplyId, messageReplyName);
		}
	}

	window._messageReplySelectedSearch = _messageReplySelectedSearch;
	window.__messageReplySelected = __messageReplySelected;
	window.openMessageReplyListPanel = openMessageReplyListPanel;
})(jQuery);
